// 访问 token 缓存的 key
const ACCESS_TOKEN_KEY = "access_token";
// 刷新 token 缓存的 key
const REFRESH_TOKEN_KEY = "refresh_token";

function getAccessToken(): string {
  return localStorage.getItem(ACCESS_TOKEN_KEY) || "";
}

function setAccessToken(token: string) {
  localStorage.setItem(ACCESS_TOKEN_KEY, token);
}

function getRefreshToken(): string {
  return localStorage.getItem(REFRESH_TOKEN_KEY) || "";
}

function setRefreshToken(token: string) {
  localStorage.setItem(REFRESH_TOKEN_KEY, token);
}

function clearToken() {
  localStorage.removeItem(ACCESS_TOKEN_KEY);
  localStorage.removeItem(REFRESH_TOKEN_KEY);
}

function storeSetUserIdentity(data: { username: string; password: string }) {
  localStorage.setItem("userIdentity", JSON.stringify(data));
}

function storeGetUserIdentity(): { username: string; password: string } {
  return JSON.parse(localStorage.getItem("userIdentity") || "{}");
}
function storeSetSelectIdentityVisible(visible: boolean) {
  localStorage.setItem("selectIdentityDialogVisible", visible.toString());
}
function storeGetSelectIdentityVisible(): boolean {
  return localStorage.getItem("selectIdentityDialogVisible") === "true";
}
// 存储用户类型
// 10: "平台方",
// 21: "装修公司",
// 22: "家居建材",
// 23: "设计师",
// 24: "从业人员",
// 30: "消费者",
function storeSetUserType(userType: number) {
  localStorage.setItem("userType", userType.toString());
}
function storeGetUserType(): string {
  return localStorage.getItem("userType") || "0";
}
// status
// "-1": "未找到": 说明要填写资料
//   0: "未审核": 资料还在等待审批
//   1: "入驻通过": 资料审核通过
//   2: "入驻失败": 资料审核失败, 需要重新填写
function storeSetMerchantStatus(status: number) {
  console.log(status);

  localStorage.setItem("merchantStatus", status.toString());
}
function storeGetMerchantStatus(): number {
  return parseInt(localStorage.getItem("merchantStatus") || "0");
}
function clearAllStore() {
  localStorage.clear();
}
export {
  getAccessToken,
  setAccessToken,
  clearToken,
  getRefreshToken,
  setRefreshToken,
  storeSetUserIdentity,
  storeGetUserIdentity,
  storeSetSelectIdentityVisible,
  storeGetSelectIdentityVisible,
  storeSetUserType,
  storeGetUserType,
  storeSetMerchantStatus,
  storeGetMerchantStatus,
  clearAllStore,
};
